import { createStore } from 'vuex'

import { vue, react, wechat, across, compileBuild } from '../constants/docs'
import { frontEndTools, OfficeTools } from '../constants/tools'
import { tools, docs, community } from '../constants/asideData'
import { blogs } from '../constants/community'

const store = createStore({
    state: {
        asideData: [],
        mainData: [],
    },
    mutations: {
        setAsideData(state, key) {
            const asideActions = {
                tools: tools,
                docs: docs,
                community: community,
            }
            state.asideData = asideActions[key]
        },
        setMainData(state, menuItemText) {
            const actions = new Map([
                // 工具
                ['前端工具', frontEndTools],
                ['办公工具', OfficeTools],
                // 文档
                ['vue', vue],
                ['react', react],
                ['微信开发', wechat],
                ['跨端框架', across],
                ['编译构建', compileBuild],
                // 社区
                ['博客', blogs],
            ])

            state.mainData = actions.get(menuItemText)
        },
    },
    actions: {},
    modules: {},
})

export default store
